package com.ruoyi.web.controller.sms;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SmsIntegralRule;
import com.ruoyi.system.service.ISmsIntegralRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 奖励规则Controller
 *
 * @author DRIES
 * @date 2022-03-09
 */
@RestController
@RequestMapping("/sms/rule")
public class SmsIntegralRuleController extends BaseController
{
    @Autowired
    private ISmsIntegralRuleService smsIntegralRuleService;

    /**
     * 查询奖励规则列表
     */
    @PreAuthorize("@ss.hasPermi('sms:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsIntegralRule smsIntegralRule)
    {
        startPage();
        List<SmsIntegralRule> list = smsIntegralRuleService.selectSmsIntegralRuleList(smsIntegralRule);
        return getDataTable(list);
    }

    /**
     * 导出奖励规则列表
     */
    @PreAuthorize("@ss.hasPermi('sms:rule:export')")
    @Log(title = "奖励规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsIntegralRule smsIntegralRule)
    {
        List<SmsIntegralRule> list = smsIntegralRuleService.selectSmsIntegralRuleList(smsIntegralRule);
        ExcelUtil<SmsIntegralRule> util = new ExcelUtil<SmsIntegralRule>(SmsIntegralRule.class);
        util.exportExcel(response, list, "奖励规则数据");
    }

    /**
     * 获取奖励规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('sms:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsIntegralRuleService.selectSmsIntegralRuleById(id));
    }

    /**
     * 新增奖励规则
     */
    @PreAuthorize("@ss.hasPermi('sms:rule:add')")
    @Log(title = "奖励规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsIntegralRule smsIntegralRule)
    {
        return toAjax(smsIntegralRuleService.insertSmsIntegralRule(smsIntegralRule));
    }

    /**
     * 修改奖励规则
     */
    @PreAuthorize("@ss.hasPermi('sms:rule:edit')")
    @Log(title = "奖励规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsIntegralRule smsIntegralRule)
    {
        return toAjax(smsIntegralRuleService.updateSmsIntegralRule(smsIntegralRule));
    }

    /**
     * 删除奖励规则
     */
    @PreAuthorize("@ss.hasPermi('sms:rule:remove')")
    @Log(title = "奖励规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsIntegralRuleService.deleteSmsIntegralRuleByIds(ids));
    }
}
